import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '@/views/system/login/login'
import register from '@/views/system/register/register'
import main from '@/views/layout/index'
import index from '@/views/system/index/index'
import admin from '@/views/system/admin/admin'
import user from '@/views/system/user/user'
import finance from '@/views/system/finance/finance'
import property from '@/views/system/property/property'
import chargeType from '@/views/system/chargeType/chargeType'
import charge from '@/views/system/charge/charge'
import userCharge from '@/views/system/charge/userCharge'
import negative from '@/views/system/negative/negative'
import userNegative from '@/views/system/negative/userNegative'
import space from '@/views/system/space/space'
import houses from '@/views/system/houses/houses'
import environment from '@/views/system/environment/environment'
import repair from '@/views/system/repair/repair'
import complain from '@/views/system/complain/complain'
import dispute from '@/views/system/dispute/dispute'
import goods from '@/views/system/goods/goods'
import post from '@/views/system/post/post'
import region from '@/views/system/region/region'
import message from '@/views/system/message/message'
import center from '@/views/system/center/center'
import error404 from '@/views/error/404'

Vue.use(VueRouter)

const routes = [
  {
    path: "",
    name: 'main',
    component: main,
    redirect: '/index',
    children: [
      {
        path: 'index',
        name: '首页',
        component: index
      },
      {
        path: 'admin',
        name: '管理员管理',
        component: admin
      },
      {
        path: 'property',
        name: '业主管理',
        component: property
      },
      {
        path: 'finance',
        name: '财务人员管理',
        component: finance
      },
      {
        path: 'user',
        name: '物业管理员管理',
        component: user
      },
      {
        path: 'chargeType',
        name: '收费类型管理',
        component: chargeType
      },
      {
        path: 'charge',
        name: '收费管理',
        component: charge
      },
      {
        path: 'userCharge',
        name: '缴费信息',
        component: userCharge
      },
      {
        path: 'negative',
        name: '欠费通知',
        component: negative
      },
      {
        path: 'userNegative',
        name: '欠费通知',
        component: userNegative
      },
      {
        path: 'space',
        name: '车位信息',
        component: space
      },
      {
        path: 'houses',
        name: '房屋信息',
        component: houses
      },
      {
        path: 'environment',
        name: '环境信息',
        component: environment
      },
      {
        path: 'repair',
        name: '报修申请',
        component: repair
      },
      {
        path: 'complain',
        name: '业主投诉',
        component: complain
      },
      {
        path: 'dispute',
        name: '小区民间纠纷',
        component: dispute
      },
      {
        path: 'goods',
        name: '物品管理',
        component: goods
      },
      {
        path: 'post',
        name: '职位管理',
        component: post
      },
      {
        path: 'region',
        name: '区域管理',
        component: region
      },
      {
        path: 'message',
        name: '消息通知',
        component: message
      },
      {
        path: 'center',
        name: '个人中心',
        component: center
      }
    ]
  },
  {
    path: '/login',
    name: '登陆',
    component: login,
  },
  {
    path: '/register',
    name: '注册',
    component: register,
  },
  {
    path: '/404',
    name: '404',
    component: error404,
  }
]

// 防止连续点击多次路由报错
let routerPush = VueRouter.prototype.push;
let routerReplace = VueRouter.prototype.replace;
// push
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}
// replace
VueRouter.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch(err => err)
}

const router = new VueRouter({
  mode: 'hash',
  routes,
})

export default router
